Computes the average of a view of Decimal values that are obtained by invoking a transform function on each element of the source view.

Namespace:  C1.LiveLinq
Assembly:  C1.LiveLinq (in C1.LiveLinq.dll)

Syntax

C#
public static AggregationView<TSource, decimal> LiveAverage<TSource>(
	this View<TSource> source,
	Expression<Func<TSource, decimal>> selector
)
Visual Basic
<ExtensionAttribute> _
Public Shared Function LiveAverage(Of TSource) ( _
	source As View(Of TSource), _
	selector As Expression(Of Func(Of TSource, Decimal)) _
) As AggregationView(Of TSource, Decimal)

Parameters

source
Type: C1.LiveLinq.LiveViews..::..View<(Of <(<'TSource>)>)>
A view containing the values to calculate the average of.
selector
Type: System.Linq.Expressions..::..Expression<(Of <(<'Func<(Of <(<'TSource, Decimal>)>)>>)>)>
A transform function to apply to each element.

Type Parameters

TSource
The type of the elements of source.

Return Value

A view representing the average of the values.

Remarks

If the source is empty, an InvalidOperationException is thrown.

It is possible to use standard LINQ query operator Average instead of LiveAverage. Both are "live" in the sense that they are recomputed automatically when any change occurs in the source. The difference is that Average will every time loop through the entire source collection and aggregate it from scratch, whereas LiveAverage will use a more performant algorithm, will maintain its value incrementally, processing only those source items that actually changed.

See Also